// file-upload.controller.ts
import {
  Controller,
  Post,
  UseInterceptors,
  UploadedFile,
  Req,
  Get,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { FileUploadService } from './file-upload.service';
import { CustomeFile } from './entities/file-upload.entity';
import { LogAction } from 'src/auth/utils/logging.metadata';

@Controller('file-upload')
export class FileUploadController {
  constructor(private readonly fileUploadService: FileUploadService) {}

  @LogAction('上传文件')
  @Post('upload')
  @UseInterceptors(FileInterceptor('file')) // 'file' 是表单字段名
  async uploadFile(
    @UploadedFile() file: Express.Multer.File,
    @Req() req: AuthRequest,
  ): Promise<CustomeFile> {
    return this.fileUploadService.handleFileUpload(file, req.user.userId);
  }
  // 获取文件列表
  @Get('list')
  async getFileList(): Promise<CustomeFile[]> {
    return this.fileUploadService.getFileList();
  }
}
